home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 April: Mac OS SDK / Dev.CD Apr 97 SDK1.toast / Development Kits (Disc 1) / Installer SDK Cornucopia 1.0.2 / Script Examples / Simple Atom Extender / DirectCopyScriptCheckExt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-26  |  3.2 KB  |  98 lines  |  [TEXT/MPS ]

  1. //
  2. //    File:        InstaCompOneScriptCheckExt.c
  3. //
  4. //                This file contains the source code for the DirectCopy File/Resource Info
  5. //                ScriptCheck extension function.  Since our source files are in the regular
  6. //                format (not compressed or otherwise changed and unreadable by normal
  7. //                means) we can get the information we need directly from them.  If you are
  8. //                writing your own ScriptCheck extension for your own file format, you will
  9. //                need to provide routines that know how to read your file format.
  10. //
  11. //    Copyright:    © 1996 by Apple Computer, Inc., all rights reserved.
  12. //
  13. //
  14.  
  15.  
  16. #include "TargetInfoMgt.h"
  17.  
  18. #include <Errors.h>
  19. #include <Files.h>
  20. #include <Resources.h>
  21.  
  22.  
  23. OSErr main( TargetInfoPBPtr theTargetInfoPBPtr )
  24. {
  25.     OSErr            theErr                     = noErr;
  26.     short            savedResFile             = CurResFile();
  27.     short            resAttrs;
  28.     long            resSize;
  29.     Handle            theResourceHdl;
  30.     SInt16             fileRefNum;
  31.     CInfoPBRec         theCatInfo;
  32.  
  33.  
  34.  
  35.     if( theTargetInfoPBPtr->fFileInfo.fSrcDataType                                    // If we are looking at a resource
  36.         == kDataTypeIsRsrc )    
  37.     {
  38.                                                                                     // open source file to make it cur res file
  39.         fileRefNum = HOpenResFile(    theTargetInfoPBPtr->fFileInfo.fSrcFSSpec.vRefNum,     
  40.                                     theTargetInfoPBPtr->fFileInfo.fSrcFSSpec.parID,     
  41.                                     theTargetInfoPBPtr->fFileInfo.fSrcFSSpec.name,         
  42.                                     fsRdPerm );                                            
  43.         theErr = ResError();
  44.         if (theErr != noErr) return theErr;                                                
  45.                                                                                     // get a handle to our resource
  46.         theResourceHdl = Get1Resource(    theTargetInfoPBPtr->fRsrcInfo.fSrcRsrcType, 
  47.                                         theTargetInfoPBPtr->fRsrcInfo.fSrcRsrcID);
  48.  
  49.         theErr = ResError();
  50.         if (theErr != noErr) return theErr;                                                
  51.                                     
  52.         resAttrs = GetResAttrs( theResourceHdl );                                    // get the resource attributes
  53.         
  54.         theErr = ResError();
  55.         if (theErr != noErr) return theErr;                                                
  56.  
  57.         resSize = GetResourceSizeOnDisk( theResourceHdl );                            // get resource size
  58.         
  59.         theErr = ResError();
  60.         if (theErr != noErr) return theErr;                                                
  61.  
  62.         theTargetInfoPBPtr->fRsrcInfo.fTgtRsrcAttrs = resAttrs;
  63.         theTargetInfoPBPtr->fRsrcInfo.fTgtRsrcSize     = resSize;
  64.             
  65.         CloseResFile( fileRefNum );
  66.         UseResFile( savedResFile );
  67.     }
  68.     else                                                                // we're getting file info
  69.     {
  70.         theCatInfo.hFileInfo.ioFDirIndex = 0;                            // use ioNamePtr and ioDirID
  71.         theCatInfo.hFileInfo.ioDirID = 
  72.             theTargetInfoPBPtr->fFileInfo.fSrcFSSpec.parID;                // the file's parent directory
  73.         theCatInfo.hFileInfo.ioNamePtr = 
  74.             theTargetInfoPBPtr->fFileInfo.fSrcFSSpec.name;                // filename
  75.         theCatInfo.hFileInfo.ioVRefNum = 
  76.             theTargetInfoPBPtr->fFileInfo.fSrcFSSpec.vRefNum;            // 
  77.  
  78.         theErr = PBGetCatInfoSync(&theCatInfo);                                // get info about our file
  79.         
  80.         if (theErr == noErr )
  81.         {
  82.             theTargetInfoPBPtr->fFileInfo.fTgtFinderAttrs     =             // finder attributes
  83.                 theCatInfo.hFileInfo.ioFlAttrib;
  84.             theTargetInfoPBPtr->fFileInfo.fTgtDataForkSize     =             // data fork size
  85.                 theCatInfo.hFileInfo.ioFlLgLen;
  86.             theTargetInfoPBPtr->fFileInfo.fTgtRsrcForkSize     =             // resource fork size
  87.                 theCatInfo.hFileInfo.ioFlRLgLen;
  88.             theTargetInfoPBPtr->fFileInfo.fTgtCreationDate     =             // creation date
  89.                 theCatInfo.hFileInfo.ioFlCrDat;
  90.             theTargetInfoPBPtr->fFileInfo.fTgtModDate =                 // mod date
  91.                 theCatInfo.hFileInfo.ioFlMdDat;
  92.         }
  93.  
  94.     }
  95.     
  96.     return theErr;
  97. }
  98.